#include<cstdio>
#include<cstring>
const int M=130000;
const int N=5000;
int f[M],w[N],v[N];
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		memset(f,0,sizeof(f));
		for(int i=1;i<=n;i++)
			scanf("%d%d",&w[i],&v[i]);
		for(int i=1;i<=n;i++)
			for(int j=m;j>=0;j--)
				if(j>=w[i]&&f[j-w[i]]+v[i]>f[j])
					f[j]=f[j-w[i]]+v[i];
		printf("%d\n",f[m]);
	}
	return 0;
}


